<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//判断二叉树是否对称
			function TreeNode(val, left, right) {
				this.val = (val === undefined ? 0 : val)
				this.left = (left === undefined ? null : left)
				this.right = (right === undefined ? null : right)
			}
			let r = new TreeNode(1,
				new TreeNode(2,
					new TreeNode(4, null, null),
					new TreeNode(5, null, null)),
				new TreeNode(3,
					new TreeNode(6, null, null),
					new TreeNode(7, null, null)));
			var isSymmetric = function (root) {
			  let check = (p, q) => {
			    if (p == null || q == null) return p==q;
			    // 每个树的右子树都与这棵树的左子树镜像对称
			    return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
			  };
			  return check(root, root);
			};
			console.log(isSymmetric(r));
		</script>
	</body>
</html>
